package com.bw.flinkstreaming.source2.job3;

import org.apache.flink.streaming.api.functions.source.ParallelSourceFunction;

/**
 * 作者QQ：43281991
 * 需求：自定义支持并行度的source
 */
public class ParallelSource implements ParallelSourceFunction<Long> {

    private long number = 10L;
    private boolean isRunning = true;

    @Override
    public void run(SourceContext<Long> ctx) throws Exception {
        while (isRunning) {
            //把数据写到下游
            ctx.collect(number);
            number++;
            //每秒写一次
            Thread.sleep(1000);
        }
    }

    @Override
    public void cancel() {
        this.isRunning = false;
    }
}
